package com.xxl.job.core.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
/**
 * file tool
 *
 * @author xuxueli 2017-12-29 17:56:48
 */
public class FileUtil {


    /**
     * delete recursively
     *
     * @param root
     * @return
     */
    public static boolean deleteRecursively(File root) {
        if (root != null && root.exists()) {
            if (root.isDirectory()) {
                File[] children = root.listFiles();
                if (children != null) {
                    for (File child : children) {
                        deleteRecursively(child);
                    }
                }
            }
            return root.delete();
        }
        return false;
    }


    public static void deleteFile(String fileName) {
        cn.hutool.core.io.FileUtil.del(fileName);
    }


    public static void writeFileContent(File file, byte[] data) {
        cn.hutool.core.io.FileUtil.writeBytes(data, file);
    }

    public static byte[] readFileContent(File file) {
        return cn.hutool.core.io.FileUtil.readBytes(file);
    }
}
